/**
 * Copyright (c) 2015 Messcat. All rights reserved.
 */
package cc.messcat.web.system;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.messcat.common.constant.CommonConstant;
import cc.messcat.common.model.ResponseBean;
import cc.messcat.common.service.BaseService;
import cc.messcat.common.util.CollectionUtil;
import cc.messcat.entity.website.WebSite;

/**
 * 用户功能处理
 * 
 * @author Panda
 * @version 1.0
 */
@Controller
@RequestMapping("/site")
public class SiteController {

	@Resource
	private BaseService<?> baseService;

	@RequestMapping(value = "addWebSite", method = RequestMethod.POST)
	@ResponseBody
	public Object addWebSite(WebSite webSite) throws Exception {
		baseService.addObject(webSite);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_ADD_SUCCESS);
	}

	@RequestMapping(value = "delWebSite/{id}", method = RequestMethod.DELETE)
	@ResponseBody
	public Object delWebSite(@PathVariable Long id) throws Exception {
		baseService.removeObject(WebSite.class,id);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_DELETE_SUCCESS);
	}

	@RequestMapping(value = "updateWebSite", method = RequestMethod.POST)
	@ResponseBody
	public Object updateWebSite(WebSite webSite) throws Exception {
		baseService.modifyObject(webSite);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_SUCCESS);
	}

	@RequestMapping(value = "getWebSite", method = RequestMethod.GET)
	@ResponseBody
	public Object getWebSite() throws Exception {
		List<WebSite> resultList = baseService.retrieveAllObjects(WebSite.class);
		WebSite webSite = null;
		if (CollectionUtil.isListNotEmpty(resultList))
			for (WebSite webSite0 : resultList) {
				if (null != webSite0.getSiteStatus() && CommonConstant.STATUS_ONE.equals(webSite0.getSiteStatus()))
					webSite = webSite0;
			}
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, webSite);
	}

	@RequestMapping(value = "getWebSiteAll", method = RequestMethod.GET)
	@ResponseBody
	public Object getWebSiteAll() throws Exception {
		List<WebSite> resultList = baseService.retrieveAllObjects(WebSite.class);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, resultList);
	}

}